<template>
	<view class="template-store tn-safe-area-inset-bottom">
		<!-- 顶部自定义导航 -->
		<!--  <tn-nav-bar fixed alpha customBack>
      <view slot="back" class='tn-custom-nav-bar__back'
        @click="goBack">
        <text class='icon tn-icon-left'></text>
        <text class='icon tn-icon-home-capsule-fill'></text>
      </view>
    </tn-nav-bar> -->

		<!-- 顶部自定义导航 -->
		<tn-nav-bar fixed :isBack="false" :bottomShadow="false" backgroundColor="#FFFFFF">
			<view class="custom-nav tn-flex tn-flex-col-center tn-flex-row-left">
				<!-- 图标logo -->
				<view class="custom-nav__back" @click="tnBack()">
					<view class="tn-icon-left"></view>
				</view>
				<!-- 搜索框 -->
				<view class="custom-nav__search tn-flex tn-flex-col-center tn-flex-row-center ">
					<view
						class="custom-nav__search__box tn-flex tn-flex-col-center tn-flex-row-left tn-color-gray--dark tn-bg-gray--light">
						<view class="custom-nav__search__icon tn-icon-search"></view>
						<view class="custom-nav__search__text tn-padding-left-xs">
							<input type="text" name="" id="" @input="searchInput" confirm-type="search" @confirm="searchSubmit">
						</view>
					</view>
				</view>
			</view>
		</tn-nav-bar>



		<view class="tn-margin-top-sm" :style="{paddingTop: vuex_custom_bar_height + 'px'}">
			<swiper class="card-swiper tn-margin-top-sm" :circular="true" :autoplay="true" duration="500" interval="5000"
				@change="cardSwiper">
				<swiper-item v-for="(item,index) in swiperList" :key="index" :class="cardCur==index?'cur':''" @click="tn(item.navigate)">
					<view class="swiper-item image-banner">
						<image :src="item.url + item.path" mode="aspectFill"></image>
					</view>
					<view class="swiper-item-text">
						<view class="tn-text-xxl tn-text-bold tn-color-white">{{item.first_title}}</view>
						<view class="tn-text-bold tn-color-white tn-padding-top-xs" style="font-size: 40rpx;">{{item.second_title}}</view>
						<view class=" tn-text-bold tn-color-red tn-padding-top-sm tn-padding-bottom-sm">
							<text class="tn-text-lg">￥</text>
							<text class="tn-text-sm">{{item.title}}</text>
						</view>
					</view>
					<view class="swiper-item-text2">
						<view class="tn-text-xxl tn-text-bold">
							<text class="tn-color-white tn-float-right tn-bg-red"
								style="border-radius: 10rpx;padding: 10rpx 20rpx;">了解更多</text>
						</view>
					</view>
				</swiper-item>
			</swiper>
			<view class="indication">
				<block v-for="(item,index) in swiperList" :key="index">
					<view class="spot" :class="cardCur==index?'active':''"></view>
				</block>
			</view>
		</view>

		<view class="">
			<view class="nav_title--wrap">
				<view class="nav_title tn-cool-bg-color-16">
					<text class="tn-icon-star tn-padding-right-sm"></text>
					资 / 料 / 列 / 表
					<text class="tn-icon-star tn-padding-left-sm"></text>
				</view>
			</view>
		</view>

		<!-- 图文 -->
		<!-- 比例 start-->
		<view class="tn-flex tn-flex-wrap tn-margin-sm">
			<block v-for="(item, index) in content" :key="index">
				<view class="" style="width: 50%;" @click="tn('/subpages/file/download/download?uid=' + item.uid)">
					<view class="tn-blogger-content__wrap">
						<view class="image-picbook" :style="'background-image:url(' + item.url + item.path + ')'">
							<view class="image-book">
							</view>
						</view>

						<view class="tn-blogger-content__label tn-text-justify tn-padding-sm">
							<text class="tn-blogger-content__label__desc">{{ item.title }}</text>
						</view>

						<view
							class="tn-flex tn-flex-row-between tn-flex-col-center tn-padding-left-sm tn-padding-right-sm tn-padding-bottom-sm">
							<view class="justify-content-item tn-text-center">
								<view
									class="tn-blogger-content__label__item tn-float-left tn-margin-right tn-bg-gray--light tn-round tn-text-sm tn-text-bold">
									<text class="tn-blogger-content__label__item--prefix">#</text> {{item.category.title}}
								</view>
							</view>
						</view>


					</view>
				</view>
			</block>
		</view>
		<!-- 比例 end-->

		<!-- 回到首页悬浮按钮-->
		<block v-if="showNav">
			<nav-index-button></nav-index-button>
		</block>
	</view>
</template>

<script>
	import template_page_mixin from '@/libs/mixin/template_page_mixin.js'
	import NavIndexButton from '@/libs/components/nav-index-button.vue'
	import {
		getResourceList
	} from "@/utils/api/file.js"
	import {
		getBannerList
	} from "@/utils/api/config.js"
	export default {
		name: 'TemplateStore',
		mixins: [template_page_mixin],
		components: {
			NavIndexButton
		},
		data() {
			return {
				showNav: false,
				cardCur: 0,
				swiperList: [],
				content: [],
				searchWhere: {
					category_uid: "",
					page: 1,
					size: 20,
					title: "",
				},
			}
		},
		onLoad(params) {
			this.searchWhere.category_uid = params.uid || ""
			this.getResourceList()
			this.getBannerList()
			this.$t.mpShare = {
				share: false,
			}
			if (!this.$t.mpShare.share) {
				uni.hideShareMenu()
			}
		},
		methods: {
			// 获取资源列表
			getResourceList(type = 1) {
				if (type == 2) {
					this.content = []
					this.searchWhere.page = 1
				}
				uni.showLoading({
					title: "数据努力加载中",
					mask: true,
				})
				getResourceList(this.searchWhere).then(res => {
					uni.hideLoading()
					if (res.code == 100) {
						this.content.push(...res.data.items)
						this.searchWhere.page = res.data.page + 1
						return
					}
					this.$func.showToast(res.msg)
				})
			},
			// 获取轮播图配置
			getBannerList() {
				getBannerList({position: "mini_file_list"}).then(res => {
					if (res.code == 100) {
						this.swiperList = res.data
						return
					}
					this.$func.showToast(res.msg)
				})
			},
			cardSwiper(e) {
				this.cardCur = e.detail.current
			},
			searchInput(e) {
				this.searchWhere.title = e.detail.value
			},
			searchSubmit(e) {
				this.getResourceList(2)
			},
			tn(e) {
				this.$func.navigatorTo(e)
			},
			tnBack() {
				uni.navigateBack()
			}
		},
		onReachBottom() {
			this.getResourceList()
		},
		onPageScroll(e) {
			let screenHeight = 500
			let sysInfo = uni.getSystemInfo({
				success(res) {
					screenHeight = res.screenHeight || 500
				}
			})
			if (e.scrollTop * 4 > screenHeight) {
				this.showNav = true
			} else {
				this.showNav = false
			}
		}
	}
</script>

<style lang="scss" scoped>
	.tn-custom-nav-bar__back {
		width: 100%;
		height: 100%;
		position: relative;
		display: flex;
		justify-content: space-evenly;
		align-items: center;
		box-sizing: border-box;
		background-color: rgba(0, 0, 0, 0.15);
		border-radius: 1000rpx;
		border: 1rpx solid rgba(255, 255, 255, 0.5);
		color: #FFFFFF;
		font-size: 18px;

		.icon {
			display: block;
			flex: 1;
			margin: auto;
			text-align: center;
		}

		&:before {
			content: " ";
			width: 1rpx;
			height: 110%;
			position: absolute;
			top: 22.5%;
			left: 0;
			right: 0;
			margin: auto;
			transform: scale(0.5);
			transform-origin: 0 0;
			pointer-events: none;
			box-sizing: border-box;
			opacity: 0.7;
			background-color: #FFFFFF;
		}
	}

	/* 自定义导航栏内容 start */
	.custom-nav {
		height: 100%;

		&__back {
			margin: auto 5rpx;
			font-size: 40rpx;
			margin-right: 10rpx;
			margin-left: 30rpx;
			flex-basis: 5%;
		}

		&__search {
			flex-basis: 60%;
			width: 100%;
			height: 100%;

			&__box {
				width: 100%;
				height: 70%;
				padding: 15rpx 0;
				margin: 0 30rpx;
				border-radius: 60rpx;
				font-size: 24rpx;
			}

			&__icon {
				padding-right: 10rpx;
				margin-left: 20rpx;
				font-size: 30rpx;
			}

			&__text {
				color: #AAAAAA;
				width: 100%;
			}
		}
	}

	/* 自定义导航栏内容 end */

	/* 轮播视觉差 start */
	.card-swiper {
		height: 400rpx !important;
	}

	.card-swiper swiper-item {
		width: 620rpx !important;
		left: 30rpx;
		box-sizing: border-box;
		padding: 0rpx 0rpx 90rpx 0rpx;
		overflow: initial;
	}

	.card-swiper swiper-item .swiper-item {
		width: 100%;
		display: block;
		height: 100%;
		border-radius: 30rpx;
		transform: scale(0.9);
		transition: all 0.2s ease-in 0s;
		overflow: hidden;
	}

	.card-swiper swiper-item.cur .swiper-item {
		transform: none;
		transition: all 0.2s ease-in 0s;
	}

	.card-swiper swiper-item .swiper-item-text {
		margin-top: -140rpx;
		width: 100%;
		display: block;
		height: 70%;
		border-radius: 10rpx;
		transform: translate(100rpx, -60rpx) scale(0.9, 0.9);
		transition: all 0.6s ease 0s;
		overflow: hidden;
	}

	.card-swiper swiper-item.cur .swiper-item-text {
		margin-top: -200rpx;
		width: 100%;
		transform: translate(0rpx, 0rpx) scale(0.9, 0.9);
		transition: all 0.6s ease 0s;
	}

	.card-swiper swiper-item .swiper-item-text2 {
		margin-top: -160rpx;
		width: 100%;
		display: block;
		height: 50%;
		border-radius: 10rpx;
		transform: translate(0rpx, 0rpx) scale(0.9, 0.9);
		transition: all 0.3s ease 0s;
		overflow: hidden;
		opacity: 0;
	}

	.card-swiper swiper-item.cur .swiper-item-text2 {
		margin-top: -120rpx;
		width: 100%;
		transform: translate(0rpx, 0rpx) scale(0.9, 0.9);
		transition: all 0.3s ease 0s;
		opacity: 1;
	}

	.image-banner {
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.image-banner image {
		width: 100%;
		height: 100%;
	}

	/* 轮播指示点 start*/
	.indication {
		z-index: 9999;
		width: 100%;
		height: 36rpx;
		position: absolute;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: center;
	}

	.spot {
		background-color: #000000;
		opacity: 0.2;
		width: 10rpx;
		height: 10rpx;
		border-radius: 40rpx;
		top: -60rpx;
		margin: 0 8rpx !important;
		position: relative;
	}

	.spot.active {
		opacity: 1;
		width: 30rpx;
		background-color: #E83A30;
	}

	.image-store {
		padding: 120rpx 0rpx;
		font-size: 40rpx;
		font-weight: 300;
		position: relative;
	}

	.image-pic {
		background-size: cover;
		background-repeat: no-repeat;
		// background-attachment:fixed;
		background-position: top;
	}

	/* 标题 start */
	.nav_title {
		-webkit-background-clip: text;
		color: transparent;

		&--wrap {
			position: relative;
			display: flex;
			height: 120rpx;
			font-size: 46rpx;
			align-items: center;
			justify-content: center;
			font-weight: bold;
			background-image: url(https://tnuiimage.tnkjapp.com/title_bg/title44.png);
			background-size: cover;
		}
	}

	/* 标题 end */

	/* 文章内容 start*/
	.tn-blogger-content {
		&__wrap {
			box-shadow: 0rpx 0rpx 50rpx 0rpx rgba(0, 0, 0, 0.12);
			border-radius: 20rpx;
			margin: 15rpx;
		}

		&__info {
			&__btn {
				margin-right: -12rpx;
				opacity: 0.5;
			}
		}

		&__label {
			&__item {
				line-height: 45rpx;
				padding: 0 20rpx;
				margin: 5rpx 18rpx 0 0;

				&--prefix {
					color: #E83A30;
					padding-right: 10rpx;
				}
			}

			&__desc {
				line-height: 35rpx;
			}
		}

		&__main-image {
			border-radius: 16rpx 16rpx 0 0;

			&--1 {
				max-width: 690rpx;
				min-width: 690rpx;
				max-height: 400rpx;
				min-height: 400rpx;
			}

			&--2 {
				max-width: 260rpx;
				max-height: 260rpx;
			}

			&--3 {
				height: 212rpx;
				width: 100%;
			}
		}

		&__count-icon {
			font-size: 30rpx;
			padding-right: 5rpx;
		}
	}

	.image-book {
		padding: 150rpx 0rpx;
		font-size: 16rpx;
		font-weight: 300;
		position: relative;
	}

	.image-picbook {
		background-size: cover;
		background-repeat: no-repeat;
		// background-attachment:fixed;
		background-position: top;
		border-radius: 20rpx 20rpx 0 0;
	}

	/* 文章内容 end*/
</style>